package com.test.dao.impl;

import com.test.dao.EmployeeDao;
import com.test.domain.Employee;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

@Repository
public class EmployeeDaoImpl implements EmployeeDao {

    @Resource
    private JdbcTemplate jdbcTemplate;

    public EmployeeDaoImpl(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    @Override
    public void insertEmployee(Employee employee) {
        System.out.println(employee);
      String sql="insert into employee values(?,?,?,?)";
      jdbcTemplate.update(sql,employee.getEmployeeNumber(),employee.getPhoneNumber(),employee.getPassword(),employee.getUsername());
    }

    @Override
    public int selectByEmployeeNumber(String employeeNumber) {

        String sql = "select count(*) from employee where employee_number=?";
        return jdbcTemplate.queryForObject(sql, Integer.class, employeeNumber);
    }

    @Override
    public String selectPasswordByEmployeeNumber(String employeeNumber) {
        String sql = "select password from employee where employee_number=?";
        return jdbcTemplate.queryForObject(sql, String.class, employeeNumber);
    }
}
